/* 引用store */
import Vue from 'vue'
import store from '@/store'
Vue.prototype.$store = store;
/* 引用store结束 */

export default {
	install: function(Vue) {
		Vue.prototype.sendSock = function(path, callback) {
			if (this.$store.state.socketOpen) {
				uni.sendSocketMessage({
					data: JSON.stringify(path)
				});
			} else {
				store.state.socketMsgQueue.push(JSON.stringify(path));
			}
			uni.onSocketMessage(function(res) {
				callback(res)
			});
		};
		// 暂存信息发送
		Vue.prototype.temporary = function(){
			for (var i = 0; i < store.state.socketMsgQueue.length; i++) {
				// 发送暂存数据
				uni.sendSocketMessage({ 
					data: store.state.socketMsgQueue[i]
				});
			}
			store.state.socketMsgQueue = []
		}
	}
};
